import {ref} from 'vue'
import {addOneGroupTopic, deleteGroup, listChatGroup, listGroup} from "@/api/weblog/chatGroup";
import {quitGroup} from "@/api/weblog/chatGroupUser";
import {ElMessage} from "element-plus";
export  const groups = ref({})
export  const currentGroupId = ref(null)

export async function exitGroup(currentGroupId) {
  let res = await quitGroup({id: currentGroupId});
      delete groups.value[currentGroupId]
      currentGroupId.value = null
      ElMessage({
        message: '退群成功！',
        type: 'success'
      })
}

export async function dissolveGroup(currentGroupId) {

  let res = await deleteGroup({id: currentGroupId});
  delete groups.value[currentGroupId]
  currentGroupId.value = null
  ElMessage({
    message: '解散群成功！',
    type: 'success'
  })
}

export  async function getImGroup() {
  let axiosResponse = await listGroup({});
  axiosResponse.data.forEach(group => {
          groups.value[group.id] = group
        })
  }

export async function addGroupTopic() {
  let res = await addOneGroupTopic({ id: currentGroupId.value });
  ElMessage.success("加入话题成功")
}


